/**
 * Program   :   ColumnDefine.java
 * Author    :   shadow guo
 * Create    :   2013-6-23 上午11:48:39
 *
 * Copyright 2008 by Tongfu Information Technology Co. Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of Tongfu Information Technology Co. Ltd. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Tongfu Information Technology Co. Ltd.
 * 
 */
package com.tongfusoft.web.utils;

import org.apache.commons.lang3.StringUtils;

public class ColumnDefine {
	private String fieldName;
	private String fieldType;
	private int scale;
	private String remark;
	
	

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}

	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}

	public String getWarpName() {
		if (StringUtils.equals("LAST_UPD_DATE", fieldName.toUpperCase())) {
			return CodeAssistTools.lastUpdDate;
		} else if (StringUtils.equals("CREATED_DATE", fieldName.toUpperCase())) {
			return CodeAssistTools.createdDate;
		} else {
			String[] warpNames = StringUtils
					.split(fieldName.toLowerCase(), "_");
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < warpNames.length; i++) {
				if (i == 0) {
					sb.append(warpNames[i]);
				} else {
					sb.append(warpNames[i].substring(0, 1).toUpperCase()
							+ warpNames[i].substring(1));
				}

			}
			return sb.toString();
		}
	}
	
	public String getJavaType() {
		if (this.getFieldType().equals("VARCHAR")
				|| this.getFieldType().equals("VARCHAR2")
				|| this.getFieldType().equals("CHAR")) {
			return "javaType=java.lang.String";
		} else if (this.getFieldType().equals("DATE")) {
			return "javaType=java.util.Date";
		} else {
			if (this.getScale() == 0) {
				return "javaType=java.lang.Integer";
			} else {
				return "javaType=java.lang.Double";
			}
		}
	}

	public String getJdbcType() {
		if (this.getFieldType().equals("VARCHAR")
				|| this.getFieldType().equals("VARCHAR2")
				|| this.getFieldType().equals("CHAR")) {
			return "jdbcType=VARCHAR";
		} else if (this.getFieldType().equals("NUMBER")) {
			return "jdbcType=NUMERIC";
		} else {
			return "jdbcType=TIME";
		}
	}
}
